package com.taotao.shop.product.controller.api;


import com.taotao.shop.common.util.PageUtils;
import com.taotao.shop.common.util.R;
import com.taotao.shop.common.valid.AddGroup;
import com.taotao.shop.common.valid.UpdateGroup;
import com.taotao.shop.common.valid.UpdateStatusGroup;
import com.taotao.shop.product.pojo.entity.PmsBrand;
import com.taotao.shop.product.service.PmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 品牌 前端控制器
 * </p>
 *
 * @author zwr
 * @since 2021-06-14
 */
@RestController
@RequestMapping("/admin/product/brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
        PmsBrand brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Validated({AddGroup.class}) @RequestBody PmsBrand brand){
        brandService.save(brand);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@Validated({UpdateGroup.class}) @RequestBody PmsBrand brand){
        brandService.updateDetail(brand);

        return R.ok();
    }

    /**
     * 修改状态
     */
    @RequestMapping("/update/status")
    public R updateStatus(@Validated(UpdateStatusGroup.class) @RequestBody PmsBrand brand){
        brandService.updateById(brand);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
        brandService.removeByIds(Arrays.asList(brandIds));
        return R.ok();
    }

}

